<?php
$dbFile = 'cms.db';
$pdo = new PDO('sqlite:' . $dbFile);

$data = json_decode(file_get_contents('php://input'), true);

if (isset($data['post_id'], $data['username'], $data['content'])) {
    $post_id = $data['post_id'];
    $username = $data['username'];
    $content = $data['content'];

    // 插入留言
    $stmt = $pdo->prepare("INSERT INTO comments (post_id, username, content) VALUES (?, ?, ?)");
    $stmt->execute([$post_id, $username, $content]);

    echo json_encode(['success' => true]);
} else {
    echo json_encode(['success' => false]);
}
